package com.cxg.fairy.ec.main.personal.score;


import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.ListViewCompat;
import android.view.View;

import com.cxg.fairy.app.AccountManager;
import com.cxg.fairy.delegates.LatteDelegate;
import com.cxg.fairy.ec.main.personal.balance.BalanceListAdapter;
import com.cxg.fairy.ec.main.personal.balance.BalanceListDataConverter;
import com.cxg.fairy.net.RestClient;
import com.cxg.fairy.net.callback.ISuccess;
import com.cxg.fairy.ui.recycler.MultipleItemEntity;
import com.diabin.latte.ec.R;
import com.diabin.latte.ec.R2;

import java.util.List;

import butterknife.BindView;


/**
 * Created by Administrator on 2018/4/18.
 */

public class ScoreListDelegate extends LatteDelegate implements ISuccess{

    @BindView(R2.id.lv_score_list)
    ListViewCompat scoreListView = null;

    private static final String SCORE_TYPE = "SCORE_TYPE";

    @Override
    public Object setLayout() {
        return R.layout.delegate_score_list;
    }

    public static ScoreListDelegate create(int cate) {
        Bundle args = new Bundle();
        args.putInt(SCORE_TYPE, cate);
        ScoreListDelegate delegate = new ScoreListDelegate();
        delegate.setArguments(args);
        return delegate;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, @NonNull View rootView) {
        RestClient.builder()
                .loader(getContext())
                .url("getMsPointByCate")
                .params("uuid", AccountManager.getSignUUID())
                .params("cate", getArguments().getInt(SCORE_TYPE))
                .success(this)
                .build()
                .post();
    }

    @Override
    public void onSuccess(String response) {
        List<MultipleItemEntity> data = new ScoreListDataConverter().setJsonData(response).convert();
        final ScoreListAdapter balanceListAdapter = new ScoreListAdapter(getContext(), R.layout.item_score_list, data);
        scoreListView.setDividerHeight(0);
        scoreListView.setAdapter(balanceListAdapter);
    }
}
